package com.hiwhitley.easy.day07;

/**
 * Created by hiwhitley on 2016/8/11.
 */
public class CanConstruct {
    public boolean canConstruct(String ransomNote, String magazine) {
        int[] table = new int[26]; // only lowercase letters
        for (char c : magazine.toCharArray()) { // 字符计数
            table[c - 'a']++;
        }
        for (char c : ransomNote.toCharArray()) { // 递减字符计数
            table[c - 'a']--;
            if (table[c - 'a'] < 0) { // 字符短缺
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {

    }
}
